{template 'web/common/header'}

<body>
    <style>
        .table-box {
            padding-bottom: 10px;
            width: 100%;
        }
        
        .detail-bottom {
            margin-top: 20px;
        }
        
        .detail-header span,
        .detail-bottom span {
            margin-right: 30px;
        }
        
        .detail-header span label,
        .detail-bottom span label {
            font-weight: 100;
        }
    </style>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">


                <div class="table-box detail-header">
                    <div class="table-cell">
                        <span><label>单号：</label>{$detail['record']}({$state[$detail['state']]})</span>
                        <span><label>制单人：</label>{$detail['originator']}</span>
                        <br>
                        <span><label>调出仓库：</label>{$detail['outstorage']}</span>
                        <span><label>调出日期：</label>{$detail['outdate']}</span>
                        <span><label>调入仓库：</label>{$detail['instorage']}</span>

                        {if $detail['indate'] && $detail['state'] == 2}
                        <span><label>调入日期：</label>{$detail['indate']}</span>
                        {else}
                        <span id="indatediv">
                            <div class="layui-inline">
                                <label class="layui-form-label">调入日期</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="outdate" placeholder="请填写调拨日期" class="layui-input" id="indate" lay-verify="required">
                                </div>
                            </div>
                            <button class="layui-btn layui-btn-normal">入库</button>
                        </span>
                        {/if}
                    </div>
                    <div class="table-cell tr"></div>
                </div>
                <div id="inTable" lay-filter="inTable"></div>
                <div class="table-box detail-bottom">
                    <div class="table-cell">
                        <span><label>经办人：</label>{$detail['transactor']}</span>
                        <span><label>备注：</label>{$detail['remark']}</span>
                    </div>
                    <div class="table-cell tr"></div>
                </div>
            </div>
        </div>
    </div>

    <script src="../addons/xn_erp/images/layuiadmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '../addons/xn_erp/images/layuiadmin/layui/extend/'
        }).use(['table', 'form', 'jquery', 'laydate', 'layer'], function() {
            var table = layui.table,
                $ = layui.$,
                form = layui.form,
                layer = layui.layer,
                laydate = layui.laydate;
            laydate.render({ elem: '#indate', type: 'datetime', value: new Date() });
            var inTable = table.render({
                elem: '#inTable',
                height: 480,
                data: JSON.parse('{$data}'),
                loading: true,
                page: true,
                text: { none: '请添加要入库的商品' },
                cols: [
                    [
                        { field: 'number', title: '商品编码', width: 100, fixed: true },
                        { field: 'name', title: '商品名称', minWidth: 200 },
                        { field: 'snumber', title: '入库数量', width: 100, },
                        { field: 'unit_name', title: '单位', width: 60 },
                        { field: 'remark', title: '备注', },
                    ]
                ],

            });

            $(".layui-btn-normal").click(function() {
                layer.confirm('是否确定要入库？', { icon: 3, title: '提示' }, function(instorage) {
                    var indate = $('#indate').val();
                    $.post('{$url}&api=in', { tid: "{$detail['id']}", indate: indate }, function(data) {

                        if (data['code'] == 0) {

                            layer.alert(data['msg']);
                            var indatespan = "<span><label>调入日期：</label>"+indate+"</span>";
                            $("#indatediv").html(indatespan);
                            layer.close(instorage);
                        }

                    });
                    // layer.close(instorage);
                });
                return false;
            });
        });
    </script>
</body>


</html>